package com.twu.biblioteca;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;

import static java.lang.Integer.parseInt;

/**
 * Created with IntelliJ IDEA.
 * User: Thoughtworker
 * Date: 8/21/13
 * Time: 10:55 AM
 * To change this template use File | Settings | File Templates.
 */
public class BookGetter {
    private BibliotecaApp app;
    private Output output;
    private Input input;

    private ArrayList<Book> books;

    public BookGetter(Output output,ArrayList<Book> books, Input input)
    {
        this.books = books;
        this.output = output;
        this.input = input;
    }


    public Book getBook(int index)
    {
        if(index >= 0 && index < books.size())
            return books.get(index);
        else
            return null;
    }

    public void checkMembership() {
        output.printPleaseTalkToLibrarianMessage();
    }

    public void reserveBook()
    {
        output.printBookToReserveMessage();

        this.showBooks();

        int index = input.getUserInput();

        Book b = this.getBook(index);
        if(b != null)
        {
            b.reserve();
            output.printThankYouMessage();
        }
        else {
            output.printBookNotAvailableMessage();
        }
    }

    public void showBooks() {
        output.printBooks(books);
    }


}































